﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Configuration;
using System.Web.Security;
using WF_Business;
using ExtBusiness.FlowOperation;
using System.Net;
using ExtBusiness.Interface;
using ExtBusiness.Common;
using ExtBusiness;
using Common;

public partial class office_OnlineTask :PageBase
{
    ClsSubmitInfo clsSubmit = new ClsSubmitInfo();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["BusinessFlag"] = Request["Business"];
            if (!string.IsNullOrEmpty(Request["iid"]))
            {
                txtIID.Value = Request["iid"];
                ViewState["BusinessFlag"] = "0";
            }

            
            if (ViewState["BusinessFlag"] == null)
            {
                BindDXCenterData();
            }
            else
            {
                //BindDXCenterData();
                BindUtInfo();
            }
            
        }
    }


    /// <summary>
    /// 获取并添加地信中心所提交数据
    /// </summary>
    /// <!--获取并添加地信中心提交的信息数据 add by zhongjian 20100303-->
    /// <!--修改为动态加载WEB SERVICE的接口调用方式 update by zhongjian 20100702-->
    private void BindDXCenterData()
    {
        WorkFlowPubSettting wfpsTemp = new WorkFlowPubSettting();
        DataTable dtTemp = wfpsTemp.GetWebService();
        if (dtTemp.Rows.Count > 0)
        {
            bool bFlag = dtTemp.Rows[0]["webflag"].ToString() == "0" ? false : true;
            if (bFlag)
            {
                InterfaceOperation infaceOperation = new InterfaceOperation();
                try
                {
                    DxInterface.IdsService idsTemp = new DxInterface.IdsService();
                    string strCheckCode = Encode.Md5(DateTime.Now.ToShortDateString());
                    //status:   0:新提交的申请；-1:已获取过的申请信息；1:已经审批结束
                    //appDateStart: 字符型，格式限定为YYYY-MM-DD
                    string strTemp = idsTemp.GetApplication("", "", "", strCheckCode);
                    DataSet dsSouseData = infaceOperation.GetDatasetFromXml(strTemp);

                    if (dsSouseData.Tables.Count > 0)
                    {
                        infaceOperation.InsertInfaceData(dsSouseData, Session["UserName"].ToString());
                    }
                }
                catch (Exception ex)
                {
                    //写入接口日志
                    string strSql = "";
                    strSql = "insert into XT_INTERFACE_RESULT (error_info,flag) values ('提示:在获取地信中心申报数据时发生异常   " + ex.ToString() + "',10)";
                    SysParams.OAConnection().RunSql(strSql);
                    //判断该用户是否有审批涉密流程的权限，如果没有则不提示。
                    string SerialFlowType = SystemConfig.InterfaceSerialName;//国家涉密基础测绘成果使用申报
                    DataTable dtTempEx = clsSubmit.GetSerialPowerByUserID(UserId);

                    for (int i = 0; i < dtTempEx.Rows.Count; ++i)
                    {
                        if (SerialFlowType.Contains(dtTempEx.Rows[i]["wname"].ToString()))
                        {
                            lblError.Text = "<font color='red'>与测绘成果分发服务辅助办公系统连接失败，无法获取国家涉密基础测绘成果使用申报的最新数据。请与管理员联系。</font>";
                            lblError.Visible = true;
                            break;
                        }
                    }
                }
            }
        }
    }

    /// <summary>
    /// 绑定待处理业务数据
    /// </summary>
    /// <!--update by zhongjian 20091019-->
    protected void BindUtInfo()
    {
        DataTable dt = clsSubmit.GetBusinessInfo(UserId, "", txtIID.Value.Trim(), txtName.Value.Trim(), ViewState["BusinessFlag"].ToString());
        gridviewCar.DataSource = dt;
        gridviewCar.RecordCount = dt.Rows.Count;
        gridviewCar.DataBind();
        if (ViewState["BusinessFlag"].ToString() == "0" || ViewState["BusinessFlag"] == null)
        {
            gridviewCar.Columns[8].Visible = false;//补正次数
            gridviewCar.Columns[9].Visible = false;//补正原因
        }
        else if (ViewState["BusinessFlag"].ToString() == "smcg")//涉密成果
        {
            gridviewCar.Columns[5].Visible = false;//图名
            gridviewCar.Columns[8].Visible = false;//补正次数
            gridviewCar.Columns[9].Visible = false;//补正原因
        }
    }

    /// <summary>
    /// datagrid数据加载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridviewCar_OnLoadData(object sender, EventArgs e)
    {
        this.BindUtInfo();
    }

    protected void btnQuery_Click(object sender, EventArgs e)
    {
        BindUtInfo();
    }

    #region 行创建
    /// <summary>
    /// 行创建
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridviewCar_RowCreated(object sender, GridViewRowEventArgs e)
    {
        switch (e.Row.RowType)
        {
            case DataControlRowType.Header:
                break;
            case DataControlRowType.DataRow:
                string strID = string.Empty;
                DataRowView rowView = e.Row.DataItem as DataRowView;
                if (rowView != null)
                {
                    HyperLink hlNewSerial = e.Row.FindControl("hlNewSerial") as HyperLink;

                    HyperLink lbtnYstg = e.Row.FindControl("hlPass") as HyperLink;
                    //LinkButton lbtnYstg = e.Row.FindControl("lbtnYstg") as LinkButton;

                    if (hlNewSerial != null)
                    {
                        hlNewSerial.NavigateUrl = string.Format("OnlineNewTask.aspx?iid={0}&sqr={1}&FlowName={2}&SbUserId={3}", rowView["iid"], rowView["username"], rowView["FLOWNAME"], rowView["userid"]);

                        if (rowView["SUBMITFLAG"].ToString() == "3")//已预审
                        {
                            //lbtnYstg.Visible = false;
                            lbtnYstg.ID = string.Format("tg{0}", rowView["iid"]);
                            lbtnYstg.Text = "不通过";
                            lbtnYstg.NavigateUrl = string.Format("javascript:Ystg('{0}',-1);", rowView["iid"]);
                        }
                        else//未预审通过
                        {
                            //hlNewSerial.Visible = false;
                            //lbtnYstg.NavigateUrl = string.Format("OnlineTask.aspx?iid={0}&Business={1}&flag=tg", rowView["iid"], ViewState["BusinessFlag"]);

                            hlNewSerial.ID = string.Format("ys{0}", rowView["iid"]);
                            hlNewSerial.Attributes.Add("style", "display:none");

                            lbtnYstg.ID = string.Format("tg{0}", rowView["iid"]);
                            lbtnYstg.NavigateUrl = string.Format("javascript:Ystg('{0}',1);", rowView["iid"]);
                            
                        }
                    }
                }
               
                break;
        }
    }
    #endregion

    //protected void lbtnYstg_Click(object sender, EventArgs e)
    //{
    //    LinkButton LButton = sender as LinkButton;
    //    string strIID=LButton.CommandArgument.ToString();
    //    ProcessYstg(strIID);
    //    BindUtInfo();
    //}

    /// <summary>
    /// 设置预审通过标志
    /// </summary>
    /// <param name="strIID">申请编号</param>
    /// <!---->
    //protected void ProcessYstg(string strIID)
    //{
    //    clsSubmit.SetYsFlag(strIID, 3);
    //    //发送消息
    //    clsSubmit.SetMsg(strIID, "预审通过");

    //    //添加操作日志，获取操作者ip地址
    //    string myIP = Common.IPOperation.GetIpAddress();
    //    SystemLogs.AddSystemLogs(UserName, "update", "预审通过编号为 " + strIID + " 的案件", "", myIP);
    //}
}
